/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.net.itsearch.gui;

import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URI;

import crawler.SearchResultEntry;

/**
 *
 * @author 格格
 */
@SuppressWarnings("serial")
public class SearchLook extends javax.swing.JPanel {

    /**
     * Creates new form SearchLook
     */
    public SearchLook() {
        initComponents();
    }
    
     public SearchLook(SearchResultEntry result) {
        initComponents();
        titleJlabel.setText(result.getTitle());
        textArea.setText(result.getText());
        url = result.getUrl();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    /** <editor-fold defaultstate="collapsed" desc="Generated Code"> */                         
    private void initComponents() {

        titleJlabel = new javax.swing.JLabel();
        jumpJbutton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        textArea = new javax.swing.JTextArea();

        titleJlabel.setText("jLabel1");

        jumpJbutton.setText("跳转");
        jumpJbutton.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                if(Desktop.isDesktopSupported()){
                    try {
                         URI uri=URI.create(url);
                         Desktop dp=Desktop.getDesktop();
                        if(dp.isSupported(Desktop.Action.BROWSE)){
                             dp.browse(uri);
                        }
                    } catch (Exception o) {
                        o.printStackTrace();
                    }
            }
                
            }
        });

        textArea.setColumns(20);
        textArea.setRows(5);
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        jScrollPane1.setViewportView(textArea);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(36, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(titleJlabel, javax.swing.GroupLayout.PREFERRED_SIZE, 522, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addComponent(jumpJbutton)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 633, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(31, 31, 31))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(titleJlabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jumpJbutton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>                        

    private String url;
         
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jumpJbutton;
    private javax.swing.JTextArea textArea;
    private javax.swing.JLabel titleJlabel;
    // End of variables declaration                   
}
